from typing import List, Optional
from sqlmodel import select, and_
from .base import BaseService
from app import models


class FootballEuropeOddsService(BaseService[models.FootballEuropeOdds]):
    """Football Europe Odds数据查询服务"""

    def __init__(self, db, current_user):
        super().__init__(db, current_user, models.FootballEuropeOdds)

    async def get_football_europe_odds_by_fid(
        self, 
        fid: int
    ) -> models.FootballEuropeOddsResultResponse:
        """
        根据fid查询football_europe_odds_500表中的所有记录
        company_id固定为293，并按create_time升序排列返回结果
        """
        try:
            # 构建查询条件
            conditions = [
                models.FootballEuropeOdds.fid == fid,
                models.FootballEuropeOdds.company_id == 293
            ]
            
            # 构建查询语句
            query = select(models.FootballEuropeOdds).where(
                and_(*conditions)
            ).order_by(models.FootballEuropeOdds.create_time.asc())
            
            # 执行查询
            result = self.db.exec(query).all()
            
            # 返回结果
            return models.FootballEuropeOddsResultResponse(
                code=0,
                message="检索成功",
                data=result
            )
        except Exception as e:
            # 异常处理
            return models.FootballEuropeOddsResultResponse(
                code=500,
                message=f"查询失败: {str(e)}",
                data=None
            )
